package com.example.demo.Expection;


import com.example.demo.comment.AppResult;
import com.example.demo.comment.Encode;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@ControllerAdvice
@RestController
public class ExceptionHandle {

    @ExceptionHandler(ApplicationException.class)
    public AppResult getApplicationException(ApplicationException e){
    System.out.println(e.getMessage());
       if(e.getMessage()==null||e.getMessage().equals("")){
           return AppResult.failed(Encode.FAILED.message);
       }
       return AppResult.failed(e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public AppResult getExceptionHandle(Exception e){
        if(e.getMessage()==null||e.getMessage().equals("")){
            return AppResult.failed(Encode.FAILED.message);
        }
        return AppResult.failed(e.getMessage());
    }


}
